<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>设置客户端的字符集</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-select-db.html">mysql_select_db</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mysql-stat.html">mysql_stat</a></div>
 <div class="up"><a href="ref.mysql.html">MySQL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mysql-set-charset" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysql_set_charset</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.3)</p><p class="refpurpose"><span class="refname">mysql_set_charset</span> &mdash; <span class="dc-title">设置客户端的字符集</span></p>

 </div>

 <div id="function.mysql-set-charset-soft-deprecation-notice" class="soft-deprecation-notice">
  <blockquote class="sidebar">
   <p class="para">本扩展自 PHP 5.5.0
起已废弃，并在将来会被移除。应使用 <a href="book.mysqli.html" class="link">MySQLi</a> 
或 <a href="ref.pdo-mysql.html" class="link">PDO_MySQL</a> 扩展来替换之。参见
<a href="mysqlinfo.api.choosing.html" class="link">MySQL：选择 API</a> 指南以及<a href="faq.databases.html#faq.databases.mysql.deprecated" class="link">相关 FAQ</a> 以获取更多信息。用以替代本函数的有：</p>
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mysqli.character-set-name.html" class="function">mysqli_character_set_name()</a></span></li>
    <li class="member">PDO: 添加 <em>charset</em> 到连接字符串，比如 <em>charset=utf8</em></li>
   </ul>
  </blockquote>
 </div>

 <div class="refsect1 description" id="refsect1-function.mysql-set-charset-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>mysql_set_charset</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$charset</code></span>
   [, <span class="methodparam"><span class="type">resource</span> <code class="parameter">$link_identifier</code><span class="initializer"> = NULL</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   设置当前连接的默认字符集。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysql-set-charset-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">charset</code></em></dt>

     <dd>

      <p class="para">
       一个有效的字符集名称。
      </p>
     </dd>

    
    <dt>
<em><code class="parameter">
link_identifier</code></em></dt>
<dd>
<p class="para">MySQL
连接。如不指定连接标识，则使用由 <span class="function"><a href="function.mysql-connect.html" class="function">mysql_connect()</a></span>
最近打开的连接。如果没有找到该连接，会尝试不带参数调用
<span class="function"><a href="function.mysql-connect.html" class="function">mysql_connect()</a></span>
来创建。如没有找到连接或无法建立连接，则会生成
<strong><code>E_WARNING</code></strong> 级别的错误。</p></dd>


   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysql-set-charset-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.mysql-set-charset-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    本函数需要 MySQL 5.0.7 或更高版本。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    这是改变字符集的最佳方式。不推荐您使用
    <span class="function"><a href="function.mysql-query.html" class="function">mysql_query()</a></span> 来设置 (比如 <em>SET NAMES utf8</em>)。
    更多信息参见 <a href="mysqlinfo.concepts.charset.html" class="link">MySQL character set concepts</a>
    一节。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysql-set-charset-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mysql-client-encoding.html" class="function" rel="rdfs-seeAlso">mysql_client_encoding()</a> - 返回字符集的名称</span></li>
    <li class="member"><a href="mysqlinfo.concepts.charset.html" class="link">Setting character sets in MySQL</a></li>
    <li class="member"><a href="http://dev.mysql.com/doc/mysql/en/charset-charsets.html" class="link external">&raquo;&nbsp;List of character sets that MySQL supports</a></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-select-db.html">mysql_select_db</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mysql-stat.html">mysql_stat</a></div>
 <div class="up"><a href="ref.mysql.html">MySQL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
